package com.cswnode.demo.util;

import com.cswnode.demo.entity.CodeMsg;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author csw
 * @create 2021/1/26 11:18
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseVo<T> implements Serializable {
    private static final Long serialVersionUID = -635302489444039690L;

    private int code;
    private String msg;
    private T data;

    public static <T> ResponseVo<T> success(){
        return new ResponseVo(CodeMsg.OK.getCode(),CodeMsg.OK.getMsg(),null);
    }

    public static <T> ResponseVo<T> success(String msg){
        return new ResponseVo(CodeMsg.OK.getCode(),msg,null);
    }

    public static <T> ResponseVo<T> success(T data){
        return new ResponseVo(CodeMsg.OK.getCode(),CodeMsg.OK.getMsg(),data);
    }

    public static <T> ResponseVo<T> success(String msg, T data){
        return new ResponseVo(CodeMsg.OK.getCode(),msg,data);
    }

    public static <T> ResponseVo<T> error(){
        return new ResponseVo<T>(400,"error",null);
    }

    public static <T> ResponseVo<T> error(String msg){
        return new ResponseVo<T>(400,msg,null);
    }

    public static <T> ResponseVo<T> error(String msg,T data){
        return new ResponseVo<T>(400,msg,data);
    }

    public static <T> ResponseVo<T> fail(int code,String msg,T data){
        return new ResponseVo<T>(code,msg,data);
    }




}
